/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package goodenglish.interfaces.videoplay;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * 
 * @author 关攀攀 panpan_001@126.com
 */
public class PlaySetingDialog extends Stage {

	public static CheckBox backGroudcheckBox;
	
	private double initX;
	private double initY;
	MediaPane mediaPane;

	static {
		backGroudcheckBox = new CheckBox("字幕是否显示背景色");
		backGroudcheckBox.setSelected(false);
	}

	public PlaySetingDialog(MediaPane mediaPane) {
		this.mediaPane = mediaPane;
		final Stage stage = new Stage(StageStyle.UNDECORATED);
		// create root node of scene, i.e. group
		Group rootGroup = new Group();
		// create scene with set width, height and color
		Scene scene = new Scene(rootGroup, 400, 400, Color.WHITESMOKE);
		// set scene to stage
		stage.setScene(scene);
		// center stage on screen
		stage.centerOnScreen();
		// show the stage
		stage.show();
		// CREATE MIN AND CLOSE BUTTONS
		// create button for closing application
		Button close = new Button("关闭");
		close.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				// in case we would like to close whole demo
				// javafx.application.Platform.exit();

				// however we want to close only this instance of stage
				stage.close();
			}
		});

		// create button for minimalising application
		Button saveBtn = new Button("应用");
		saveBtn.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				MediaGroup.subtViewLabel
						.setDisplayBackgroud(backGroudcheckBox.isSelected());
			
				stage.close();

			}
		});
		VBox vBox = new VBox();

		// when mouse button is pressed, save the initial position of screen
		rootGroup.setOnMousePressed(new EventHandler<MouseEvent>() {

			public void handle(MouseEvent me) {
				initX = me.getScreenX() - stage.getX();
				initY = me.getScreenY() - stage.getY();
			}
		});

		// when screen is dragged, translate it accordingly
		rootGroup.setOnMouseDragged(new EventHandler<MouseEvent>() {

			public void handle(MouseEvent me) {
				stage.setX(me.getScreenX() - initX);
				stage.setY(me.getScreenY() - initY);
			}
		});

		vBox.setSpacing(10);
		vBox.setPadding(new Insets(60, 0, 0, 20));
		vBox.setAlignment(Pos.TOP_CENTER);

		addMy(vBox);
		vBox.getChildren().addAll(saveBtn, close);

		// add all nodes to main root group
		rootGroup.getChildren().addAll(vBox);
	}

	private void addMy(VBox vBox) {
		vBox.getChildren().add(backGroudcheckBox);
		
	}
}
